// 所有的权限拦截操作
import router from "./router";
import store from "./store";
import NProgress from "nprogress";
import 'nprogress/nprogress.css'
// 来一个白名单
const whiteList = ['/login', '/404']
// 来一个路由前置守卫
router.beforeEach(async (to, from, next)=> {
  NProgress.start()
  // 开始判断操作
  if (store.getters.token) {
    if (to.path === '/login') {
    
      next('/')
    } else {
        /* 看是否有用户的资料 */
        if (!store.getters.userId) {
        const {roles}=  await store.dispatch('user/getUserInfo')
        }
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) > -1) {
      next()
    } else {
      next('/login')
    }
  }
  NProgress.done()
})
// 来一一个路由后置守卫
router.afterEach(function () {
  NProgress.done()
})